#!/bin/bash

hive_db_name=movie_dataset
mysql_db_name=movie

export_data() {
/opt/module/sqoop/bin/sqoop export \
--connect "jdbc:mysql://hadoop102:3306/${mysql_db_name}?useUnicode=true&characterEncoding=utf-8"  \
--username root \
--password 000000 \
--table $1 \
--export-dir /user/hive/warehouse/movie_dataset.db/$1 \
--input-fields-terminated-by "," \
--update-mode allowinsert \
--input-null-string '\\N'    \
--input-null-non-string '\\N'
}

case $1 in
  "result1" )
    export_data "result1"
  ;;

  "result2" )
    export_data "result2"
  ;;

  "result3" )
    export_data "result3"
  ;;

  "result4" )
    export_data "result4"
  ;;

  "result5" )
    export_data "result5"
  ;;

  "all" )
    export_data "result1"
    export_data "result2"
    export_data "result3"
    export_data "result4"
    export_data "result5"
  ;;
esac
